<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <textarea name="" id="" cols="30" rows="10"></textarea>
    <button>提交</button>
    <div></div>
    <script>
      var str = "andy和red";
      //   var newStr = str.replace("andy", "baby");
      var newStr = str.replace(/andy/, "baby");
      var btn = document.querySelector("button");
      var text = document.querySelector("textarea");
      var div = document.querySelector("div");
      btn.onclick = function () {
        div.innerHTML = text.value.replace(/激情|gay/g, "**"); // g 表示全局匹配
      };
    </script>
  </body>
</html>
